import request from '@/http/http'

// 获取所有权限
export const getAllPermissions = async () => {
    console.log(`准备获取所有权限列表`);
    return request({
        url: 'BaseDataReadAPI/Permission/GetAllPermissiont',
        method: 'GET'
    })
}

// 获取角色权限
export const getRolePermissionList = async (roleId: number) => {
    console.log(`准备获取角色ID为 ${roleId} 的权限列表`);
    return request({
        url: 'BaseDataReadAPI/Permission/GetPermissiont',
        method: 'get',
        params: {
            roleId: roleId
        }
    })
}

// 获取菜单权限树
export const getMenuPermission = async (parentId: number = 0) => {
    console.log(`准备获取ParentId为 ${parentId} 的菜单权限`);
    return request({
        url: 'BaseDataReadAPI/Permission/GetMenuPermission',
        method: 'get',
        params: {
            parentId: parentId
        }
    })
}

// 设置角色权限参数接口
export interface SetRolePermissionParams {
    RoleId: number        // 角色ID
    PermissionIds: number[] // 权限ID列表
}

// 设置角色权限
export const setRolePermission = async (data: SetRolePermissionParams) => {
    console.log(`准备设置角色ID为 ${data.RoleId} 的权限列表:`, data.PermissionIds);
    return request({
        url: 'BaseDataWriteAPI/Permission/SetPermission',
        method: 'POST',
        data
    })
}

// 菜单权限项接口
export interface MenuPermissionItem {
    PermissionId: number;
    DisplayName: string;
    Category: string;
    Pagepath: string | null;
    ParentId: number;
    Children?: MenuPermissionItem[];
}

// 权限详情项接口
export interface PermissionDetail {
    PermissionId: number;
    DisplayName: string;
    Category: string;
    Pagepath: string | null;
    Type: string;
}


// 获取菜单权限详情
export const getMenuPermissionDetail = async (parentId: number) => {
    console.log(`准备获取菜单ID为 ${parentId} 的权限详情`);
    return request({
        url: 'BaseDataReadAPI/Permission/GetMenuPermission',
        method: 'get',
        params: {
            parentId: parentId
        }
    })
}
